<template>
  <div>
    <div>
   
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55"></el-table-column>-->
      <el-table-column prop="ID" label="序号" width="60">
         <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
      <el-table-column prop="name" label="基本信息" width="260">
        <template slot-scope="scope" >
          <div>名称：{{scope.row.name}}</div>
          <div>联系方式：{{scope.row.tel}}</div>
          <div>营业时间：{{scope.row.business_time}}</div>
          <div>地址：{{scope.row.position}}</div>
        </template>
      </el-table-column>
      <el-table-column prop="tui" label="内容">
        <template slot-scope="scope">
          <div style="margin:15px 0">
            <div>logo/封面/图片</div>
            <div>
              <img :src="scope.row.logo_url" @click="showImage(scope.row.logo_url)" style="margin-right:5px;width:70px;height:80px"/>
              <img v-for="(item,index)  in scope.row.images" :src="item" :key="index" @click="showImage(item)" style="margin-right:5px;width:70px;height:80px"/>
            </div>
          </div>
          <div>反馈信息：<span style="color:red">{{scope.row.audit_result}}</span></div>
        </template>
      </el-table-column>
     
      <el-table-column prop="tui" label="状态" width="80">
        <template  slot-scope="scope">
          <span style="color:#67c23a" v-if="scope.row.status == 1">已通过</span>
          <span style="color:red" v-else-if="scope.row.status == 2" >未通过</span>
          <span v-else >待审核</span>
        </template>
      </el-table-column>

      <el-table-column width="150" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button class="addBtn" type="success" v-if="userRole.HPT_IF_1702002 && scope.row.status != 1 " @click="passsFun(scope.row.hospital_id,scope.row.id)">通过</el-button>
            <el-button class="addBtn" type="warning" v-if="userRole.HPT_IF_1702001 " @click="addInfo(scope.row.hospital_id,scope.row.id)">反馈</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    </div>
    
    <el-dialog :visible.sync="showSta">
      <img width="100%" :src="showImgeUrl" alt="">
    </el-dialog>

    <el-dialog title="反馈内容" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
      <div>
        <el-input type="textarea" :rows="3" placeholder="请输入反馈内容" v-model="result_msg"> </el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addSpeakFun">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        id:'',
        dialogVisible:false,
        result_msg:'',
        dataPush:'',
        newId:'',
        showSta:false,
        showImgeUrl:'',
      }
    },
    props:['tableData'],
    created(){
    },
    methods: {
      handleSelectionChange(){},
      showImage(row) {
        this.showImgeUrl = row ; 
        this.showSta = true
      },
      addInfo(row,id){
        this.id = row;
        this.newId = id;
        this.dialogVisible = true;
      },
      passsFun(row,id) {
        const obj = {
          "status":1,
          "hospital_id":row,
          "id":id
        };
        this.ajaxFun(obj)
      },
      
      ajaxFun(obj) {
         Http.auditHospital(obj)
        .then( res => {
          
          if (res.data.code == 200) {
            this.$message.success('审核成功')
            this.dialogVisible = false;
            this.$emit("getlist")
          } else {
            this.$message.error(`审核失败原因：${res.data.message}`)
          }
        })
        .catch(_ => {
          this.$message.error('服务器请求失败')
        });
      },
      addSpeakFun(){
        if(!this.result_msg){
          this.$message.error('请输入反馈内容');
          return
        }
        const obj = {
          "status":2,
          "hospital_id":this.id,
          "audit_result":this.result_msg,
          "id":this.newId
        };
        this.ajaxFun(obj)
      },
      handleClose(){
        this.dialogVisible = false;
      }
    }
  }
</script>
